import 'package:dio/dio.dart';

/**
 * 名称：我的页面
 */
import 'package:flutter/material.dart';
import 'package:flutter_todo_2019/page/setting/setting_screen.dart';
import 'package:flutter_todo_2019/page/utils/GlobalInfo.dart';
import 'package:flutter_todo_2019/page/utils/route_util.dart';
import 'package:flutter_todo_2019/page/utils/theme_util.dart';
import 'package:flutter_todo_2019/page/utils/toast_util.dart';
import 'package:flutter_todo_2019/page/utils/utils.dart';
import 'package:flutter_todo_2019/test/anim/MyFadeTest.dart';
import 'package:flutter_todo_2019/test/list/list/movie_list_page.dart';

///数据源
final GlobalInfo globalInfo = new GlobalInfo();

///TODO 我的  已经废弃
class MinePage extends StatelessWidget {
  final title;

  const MinePage({Key key, this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    var headRightView = new Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        new Padding(
          padding: new EdgeInsets.fromLTRB(3.0, 20.0, 0, 0),
          child: new Text(
            globalInfo.userName,
            style: new TextStyle(
              fontSize: 15.0,
              color: Colors.black,
            ),
          ),
        ),
        new Padding(
          padding: new EdgeInsets.fromLTRB(3.0, 4.0, 0, 0),
          child: new Text(
            globalInfo.bottomText,
            style: new TextStyle(
              fontSize: 14.0,
              color: Colors.redAccent,
            ),
          ),
        ),
      ],
    );
//    头部View
    var head = new Container(
      height: 50,
      width: 50,
      alignment: Alignment.center,
      margin: const EdgeInsets.fromLTRB(15.0, 20.0, 15, 20),
      child: Image.network(
        globalInfo.headUrl,
      ),
      decoration: new BoxDecoration(
        borderRadius: new BorderRadius.circular(5.0),
        color: ThemeUtils.currentThemeColor,
      ),
    );
    var userHeadItem = new Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.max,
      children: <Widget>[
        head,
        new Expanded(
          child: headRightView,
        ),
      ],
    );
//    进度Item View

//我的清单列表
    var myItemToDoList = new Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: <Widget>[
        Container(
          padding: new EdgeInsets.fromLTRB(15.0, 8.0, 6.0, 6.0),
          child: new Text("我的清单列表",
              style: TextStyle(
                fontSize: 14,
              )),
        ),
        IconButton(
            alignment: Alignment.center,
            icon: Icon(Icons.import_contacts, color: Colors.amber, size: 24.0),
            onPressed: () => jumpListPage(context)),
      ],
    );

    var myItemToDoChildRootView = new Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: <Widget>[
        getMyToDoItemChildView("FLAGS", "10个"),
        getMyToDoItemChildView("已完成", "2个"),
        getMyToDoItemChildView("未完成", "8个"),
      ],
    );

//    添加北京
    var paint = new Paint();
    paint.color = Colors.red;
    var bottomView = new Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        new Padding(
          padding: new EdgeInsets.fromLTRB(
              MediaQuery.of(context).size.width / 2.0 - 90, 80, 0, 20),
          child: new Text(
            "我的清单生活有效更有料",
            style: new TextStyle(
                fontSize: 18.0, color: Colors.white, background: paint),
          ),
        ),
      ],
    );

    var bottomCard = new Container(
        height: 36.0,
        alignment: Alignment.center,
        margin: const EdgeInsets.fromLTRB(20.0, 50, 20, 0),
        padding: const EdgeInsets.all(2.0),
        decoration: new BoxDecoration(
          borderRadius: new BorderRadius.circular(5.0),
          color: ThemeUtils.currentThemeColor,
        ),
        child: new Text(
          "我的清单生活有效更有料",
          style: new TextStyle(fontSize: 15.0, color: Colors.white),
        ));
//    整体View
    var itemRootView = new Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.max,
        children: <Widget>[
          userHeadItem,
          getRowItemView("2019，这是我持续成长的第10天", Icons.favorite, context),
          new Padding(
            padding: new EdgeInsets.fromLTRB(0, 8.0, 0, 8.0),
            child: new Divider(height: 2.0),
          ),
          myItemToDoList,
          Divider(indent: 2),
          myItemToDoChildRootView,
          new Padding(
            padding: new EdgeInsets.fromLTRB(0, 10.0, 0, 6.0),
            child: new Divider(height: 2.0),
          ),
          getRowItemView("觉得不错？推荐给好友", Icons.share, context),
          new Padding(
            padding: new EdgeInsets.fromLTRB(0, 8.0, 0, 8.0),
            child: new Divider(height: 2.0),
          ),
          getRowItemView("意见反馈", null, context),
          bottomCard,
        ]);

    //TODO  我在这里
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(title,
            style: TextStyle(color: Colors.white, fontSize: 18)),
        centerTitle: true,
        actions: <Widget>[
          new IconButton(
              icon: ImageIcon(
                AssetImage(Utils.getImgPath("icon_more")),
                color: Colors.white,
              ),
              onPressed: () {
                RouteUtil.jumpPage(context, new SettingScreen());
              }),
        ],
      ),
      body: itemRootView,
//        floatingActionButton: new FloatingActionButton(
//          backgroundColor: Colors.redAccent,
//          child: new Icon(Icons.brush),
//          onPressed: () {
////            jumpLoginPage(context);
//          },
//        )
    );
  }

//跳转其他界面
  jumpListPage(BuildContext context) {
    RouteUtil.jumpPage(context, new MovieListPage());
  }

  //得到 中间的ToDoList Item View
  getMyToDoItemChildView(itemKey, itemValue) {
    var itemView = new Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        new Padding(
          padding: new EdgeInsets.fromLTRB(18.0, 10.0, 18.0, 0),
          child: new Text(
            itemKey,
            style: new TextStyle(
              fontSize: 15.0,
              color: Colors.black,
            ),
          ),
        ),
        new Padding(
          padding: new EdgeInsets.fromLTRB(18.0, 8.0, 18.0, 0),
          child: new Text(
            itemValue,
            style: new TextStyle(
              fontSize: 14.0,
              color: Colors.redAccent,
            ),
          ),
        ),
      ],
    );
    return itemView;
  }

  //水平方向的ItemView
  getRowItemView(keyText, valueImg, mContext) {
    var showFinalText = (valueImg == Icons.favorite) ? "给自己点个赞" : "分享给其他小伙伴";
    var itemRowView = new Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Container(
            margin: const EdgeInsets.fromLTRB(15.0, 0, 5.0, 2.0),
            child: Text(
              keyText,
              style: new TextStyle(fontSize: 14.0, color: Colors.black),
            ),
          ),
          IconButton(
              icon: Icon(
                valueImg,
                size: 20.0,
                color: valueImg == Icons.favorite
                    ? Colors.red
                    : Colors.lightBlueAccent,
              ),
              onPressed: () =>
                  valueImg != null ? clickImg(mContext, showFinalText) : null)
        ]);
    return itemRowView;
  }

  //点击了Icon
  clickImg(mContext, String showFinalText) {
    T.show(msg: showFinalText);
  }

  //跳转其他界面
  jumpAnimPage(BuildContext context) async {
    Navigator.of(context)
        .push(new MaterialPageRoute(builder: (BuildContext context) {
      return new MyFadeTest(
        title: "动画简单测试",
      );
      ;
    }));
  }


}
